package com.ebook.core.util;

import java.sql.Timestamp;
import java.util.Map;

import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;

import com.ebook.core.domain.User;
import com.ebook.util.DateUtil;

public class UserUtil {
	
	private static Log logger = LogFactory.getLog(UserUtil.class); 
	
	/**
	 * 把Map里的用户信息复制到User对象中
	 * 
	 * @param map
	 * @return User对象
	 */
	public static User parseUser(Map<String, Object> map) {
		try {
			int id = (Integer) map.get("id");
			String name = (String) map.get("name");
			String email = (String) map.get("email");
			String password = (String) map.get("password");
			String type = String.valueOf((Integer) map.get("type"));
			Timestamp ts = (Timestamp) map.get("reg_time");
			String regTime = DateUtil.SDF2.format(ts);
			return new User(id, email, name, password, type, regTime);
		} catch (Exception e) {
			logger.error("创建User对象失败" + e.getMessage());
			return null;
		}
	}
}
